home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / progem.arc / sources.arc / GMCL16.C < prev    next >
Encoding:
Text File  |  1987-10-05  |  9.0 KB  |  404 lines

  1. >>>>>>>>>>>>>>>>>>>>> Progress box setup and cleanup <<<<<<<<<<<<<<<<<<<<<
  2.  
  3. /*------------------------------*/
  4. /*    beg_prog         */
  5. /*------------------------------*/
  6.     VOID
  7. beg_prog(rect)
  8.     GRECT    *rect;
  9.     {
  10.     OBJECT    *tree;
  11.     WORD    xdial, ydial, wdial, hdial;
  12.  
  13.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  14.     form_center(tree, &rect->g_x, &rect->g_y, &rect->g_w, &rect->g_h);
  15.     form_dial(0, 0, 0, 0, 0, rect->g_x, rect->g_y, 
  16.         rect->g_w, rect->g_h);
  17.     objc_draw(tree, ROOT, MAX_DEPTH, rect->g_x, rect->g_y, 
  18.         rect->g_w, rect->g_h);
  19.     }
  20.  
  21. /*------------------------------*/
  22. /*    end_prog         */
  23. /*------------------------------*/
  24.     VOID
  25. end_prog(rect)
  26.     GRECT    *rect;
  27.     {
  28.     form_dial(3, 0, 0, 0, 0, rect->g_x, rect->g_y, rect->g_w, rect->g_h);
  29.     }
  30.  
  31. >>>>>>>>>>>>>>>>>>>> Text line progress indicator <<<<<<<<<<<<<<<<<<<<<<<
  32.  
  33. /*------------------------------*/
  34. /*    set_prog         */
  35. /*------------------------------*/
  36.     VOID
  37. set_prog(strno)
  38.     UWORD    strno;
  39.     {
  40.     OBJECT    *tree;
  41.     BYTE    *saddr;
  42.  
  43.     rsrc_gaddr(R_TREE, STRINGS, &tree);
  44.     saddr = (BYTE *) (tree + strno)->ob_spec;
  45.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  46.     set_text(tree, PLINE, saddr);
  47.     disp_obj(tree, PLINE);
  48.     }
  49.  
  50.  
  51. >>>>>>>>>>>>>>>>>>>> Moving bar progress indicator <<<<<<<<<<<<<<<<<<<<<<
  52.  
  53. /*------------------------------*/
  54. /*    set_prog         */
  55. /*------------------------------*/
  56.     VOID
  57. set_prog(value, maxc)
  58.     WORD    value, maxc;
  59.     {
  60.     WORD    wnew, wold;
  61.     OBJECT    *tree;
  62.     GRECT    box;
  63.  
  64.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  65.     wold = (tree + PROBOX)->ob_width - 1;    /* Take border into account */
  66.     wnew = wold + 1;
  67.     if (maxc)
  68.         wnew = max(1, ((LONG) value * (LONG) wnew) / maxc); 
  69.     (tree + PROBAR)->ob_width = wnew;
  70.     if (value)
  71.         {
  72.         objc_xywh(tree, PROBAR, &box);
  73.         box.g_x += wold; box.g_w -= wold;
  74.         objc_draw(tree, ROOT, MAX_DEPTH, box.g_x, box.g_y, 
  75.             box.g_w, box.g_h);
  76.         }
  77.     }    
  78.  
  79. >>>>>>>>>>>>>>>>>>>> Progress indicator check for abort <<<<<<<<<<<<<<<<
  80.     
  81. /*------------------------------*/
  82. /*    esc_prog         */
  83. /*------------------------------*/
  84.     WORD
  85. esc_prog()
  86.     {
  87.     WORD    which, kr;
  88.     WORD    mx, my, mb, ks, br;        /* Not used, but needed */
  89.  
  90.     FOREVER 
  91.         {
  92.             which = evnt_multi(MU_KEYBD | MU_TIMER,
  93.             0, 0, 0,
  94.             0, 0, 0, 0, 0,
  95.             0, 0, 0, 0, 0,
  96.             0L, 
  97.             0, 0,        /* Zero timer delay */
  98.             &mx, &my, &mb, &ks, &kr, &br);
  99.  
  100.         if (which & MU_KEYBD)
  101.             {
  102.             if ((kr & 0xff) == 0x1B)    /* ESC?          */
  103.                 return (TRUE);        /* else try again */
  104.             }
  105.         else /* if (which & MU_TIMER) */
  106.             return (FALSE);
  107.         }
  108.  
  109.     return (TRUE);        /* Keeps lint happy */ 
  110.     }
  111.  
  112. >>>>>>>>>>>>>>>>>>>>>>> Progress subroutines  <<<<<<<<<<<<<<<<<<<<<<<
  113.  
  114.     VOID
  115. set_text(tree, obj, str)
  116.     OBJECT    *tree;
  117.     BYTE    *str;
  118.     WORD    obj;
  119.     {
  120.     TEDINFO    *obspec;
  121.  
  122.     obspec = (TEDINFO *) (tree + obj)->ob_spec;    /* Get TEDINFO address  */
  123.     obspec->te_ptext = str;            /* Set new text pointer */
  124.     obspec->te_txtlen = strlen(str);    /* Set new length    */
  125.     }
  126.  
  127.     VOID
  128. disp_obj(tree, obj)
  129.     OBJECT    *tree;
  130.     WORD    obj;
  131.     {
  132.     GRECT    box;
  133.  
  134.     objc_xywh(tree, obj, &box);
  135.     objc_draw(tree, ROOT, MAX_DEPTH, box.g_x, box.g_y, 
  136.         box.g_w, box.g_h);
  137.     }
  138.  
  139.     VOID
  140. objc_xywh(tree, obj, p)        /* get x,y,w,h for specified object    */
  141.     OBJECT    *tree;
  142.     WORD    obj;
  143.     GRECT    *p;
  144.     {
  145.     objc_offset(tree, obj, &p->g_x, &p->g_y);
  146.     p->g_w = (tree + obj)->ob_width;
  147.     p->g_h = (tree + obj)->ob_height;
  148.     }
  149.  
  150. >>>>>>>>>>>>>>>>>>>>>> Box mover examples <<<<<<<<<<<<<<<<<<<<<<<<<<
  151.  
  152. /*------------------------------*/
  153. /*    fourway_box         */
  154. /*------------------------------*/
  155.     VOID
  156. fourway_box(vdi_handle, rubber, limit)
  157.     WORD    vdi_handle;
  158.     GRECT    *rubber, *limit;
  159.     {
  160.     UWORD    ox, oy, mx, my, foo, down;
  161.  
  162.     vswr_mode(vdi_handle, MD_XOR);        /* Set VDI modes for box */
  163.     vsl_color(vdi_handle, BLACK);
  164.     wind_update(BEG_MCTRL);            /* Capture mouse     */
  165.  
  166.     ox = rubber->g_x; oy = rubber->g_y;    /* Save off input corner */
  167.     graf_mkstate(&mx, &my, &foo, &foo);    /* Initialize mouse posn */
  168.  
  169.     do {
  170.         rubber->g_x = min(ox, mx);    /* Choose UL corner     */
  171.         rubber->g_y = min(oy, my);
  172.         rubber->g_w = max(ox, mx) - rubber->g_x + 1;
  173.         rubber->g_h = max(oy, my) - rubber->g_y + 1;
  174.         rc_intersect(limit, rubber);    /* Lock into limit rect  */
  175.         down = rub_wait(vdi_handle, rubber, &mx, &my);
  176.         } while (down);
  177.  
  178.     wind_update(END_MCTRL);            /* Release mouse to GEM  */
  179.     }
  180.  
  181. /*------------------------------*/
  182. /*    hot_dragbox         */
  183. /*------------------------------*/
  184.     WORD
  185. hot_dragbox(vdi_handle, box, limit, tree)
  186.     WORD    vdi_handle;
  187.     GRECT    *box, *limit;
  188.     OBJECT    *tree;
  189.     {
  190.     UWORD    ox, oy, mx, my, foo, down;
  191.     WORD    hover_obj, ret_obj;
  192.  
  193.     vswr_mode(vdi_handle, MD_XOR);        /* Set VDI modes for box */
  194.     vsl_color(vdi_handle, BLACK);
  195.     wind_update(BEG_MCTRL);            /* Capture mouse     */
  196.  
  197.     graf_mkstate(&mx, &my, &foo, &foo);    /* Initialize mouse posn */
  198.     ox = min(box->g_w, max(0, mx - box->g_x) );
  199.     oy = min(box->g_h, max(0, my - box->g_y) );
  200.     hover_obj = NIL;
  201.  
  202.     do {
  203.         box->g_x = mx - ox;
  204.         box->g_y = my - oy;
  205.         rc_constrain(limit, box);    /* Lock into limit rect  */
  206.  
  207.         down = rub_wait(vdi_handle, box, &mx, &my);
  208.  
  209.         if (!inside(mx, my, limit))
  210.             ret_obj = NIL;
  211.         else
  212.             {
  213.             ret_obj = objc_find(tree, ROOT, NIL, mx, my);
  214.             if (ret_obj != NIL)
  215.             if ( !(SELECTABLE & (tree + ret_obj)->ob_flags) )
  216.                 ret_obj = NIL;
  217.             }
  218.  
  219.         if (ret_obj != hover_obj)
  220.             {
  221.             if (hover_obj != NIL)
  222.                 objc_toggle(tree, hover_obj);
  223.             hover_obj = ret_obj;
  224.             if (hover_obj != NIL)
  225.                 objc_toggle(tree, hover_obj);
  226.             }
  227.         } while (down);
  228.  
  229.  
  230.     wind_update(END_MCTRL);            /* Release mouse to GEM  */
  231.     if (hover_obj != NIL)
  232.         objc_toggle(tree, hover_obj);
  233.     return (hover_obj);
  234.     }
  235.  
  236. /*------------------------------*/
  237. /*    rub_wait         */
  238. /*------------------------------*/
  239.     WORD
  240. rub_wait(vdi_handle, box, mx, my)
  241.     WORD    vdi_handle;
  242.     GRECT    *box;
  243.     WORD    *mx, *my;
  244.     {
  245.     WORD    which, kr;
  246.     WORD    mb, ks, br;            /* Not used, but needed */
  247.  
  248.     graf_mouse(M_OFF, 0x0L);
  249.     vdi_xbox(vdi_handle, box);        /* Draw waiting box */
  250.     graf_mouse(M_ON, 0x0L);
  251.  
  252.            which = evnt_multi(MU_BUTTON | MU_M1,
  253.         0x01, 0x01, 0x00,        /* Wait for button up */
  254.         TRUE, *mx, *my, 1, 1,        /* or mouse move      */
  255.         0, 0, 0, 0, 0,
  256.         0L, 
  257.         0, 0,
  258.         mx, my, &mb, &ks, &kr, &br);
  259.  
  260.     graf_mouse(M_OFF, 0x0L);
  261.     vdi_xbox(vdi_handle, box);        /* Take down waiting box */
  262.     graf_mouse(M_ON, 0x0L);
  263.  
  264.     return (!(which & MU_BUTTON));        /* TRUE if still dragging */
  265.     }
  266.  
  267. >>>>>>>>>>>>>>>>>>>>>>>> Box Mover Utilities <<<<<<<<<<<<<<<<<<<<<<<<<
  268.  
  269.     VOID
  270. objc_toggle(tree, obj)
  271.     OBJECT    *tree;
  272.     WORD    obj;
  273.     {
  274.     WORD    state, newstate;
  275.     GRECT    root, ob_rect;
  276.  
  277.     objc_xywh(tree, ROOT, &root);
  278.     newstate = (tree + obj)->ob_state ^ SELECTED;
  279.     objc_change(tree, obj, 0, root.g_x, root.g_y, 
  280.         root.g_w, root.g_h, newstate, 1);
  281.     }
  282.  
  283.     VOID
  284. vdi_xbox(vdi_handle, pt)
  285.     WORD    vdi_handle;
  286.     GRECT    *pt;
  287.     {
  288.     WORD    pxy[10];
  289.  
  290.     vdi_bxpts(pt, pxy);
  291.     vdi_xline(vdi_handle, 5, pxy);
  292.     }
  293.  
  294.     VOID
  295. vdi_bxpts(pt, pxy)
  296.     GRECT    *pt;
  297.     WORD    *pxy;
  298.     {
  299.     pxy[0] = pt->g_x;
  300.     pxy[1] = pt->g_y;
  301.     pxy[2] = pt->g_x + pt->g_w - 1;
  302.     pxy[3] = pt->g_y;
  303.     pxy[4] = pt->g_x + pt->g_w - 1;
  304.     pxy[5] = pt->g_y + pt->g_h - 1;
  305.     pxy[6] = pt->g_x;
  306.     pxy[7] = pt->g_y + pt->g_h - 1;
  307.     pxy[8] = pt->g_x;
  308.     pxy[9] = pt->g_y;
  309.     }
  310.  
  311. MLOCAL    WORD    hztltbl[2] = { 0x5555, 0xaaaa };
  312. MLOCAL  WORD    verttbl[4] = { 0x5555, 0xaaaa, 0xaaaa, 0x5555 };
  313.  
  314.     VOID
  315. vdi_xline(vdi_handle, ptscount, ppoints)
  316.     WORD    vdi_handle, ptscount, *ppoints;
  317.     {
  318.     WORD        *linexy,i;
  319.     WORD        st;
  320.  
  321.     for ( i = 1; i < ptscount; i++ )
  322.         {
  323.           if ( *ppoints == *(ppoints + 2) )
  324.               {
  325.                 st = verttbl[( (( *ppoints) & 1) | 
  326.                 ((*(ppoints + 1) & 1 ) << 1))];
  327.               }    
  328.           else
  329.               {
  330.                 linexy = ( *ppoints < *( ppoints + 2 )) ? 
  331.                 ppoints : ppoints + 2;
  332.                 st = hztltbl[( *(linexy + 1) & 1)];
  333.               }
  334.  
  335.           vsl_udsty(vdi_handle, st);
  336.         vsl_type(vdi_handle, 7);
  337.           v_pline(vdi_handle, 2, ppoints);
  338.           ppoints += 2;
  339.         }
  340.  
  341.     vsl_type(vdi_handle, 1);
  342.     }    
  343.  
  344.     WORD
  345. rc_intersect(p1, p2)        /* compute intersect of two rectangles    */
  346.     GRECT    *p1, *p2;
  347.     {
  348.     WORD    tx, ty, tw, th;
  349.  
  350.     tw = min(p2->g_x + p2->g_w, p1->g_x + p1->g_w);
  351.     th = min(p2->g_y + p2->g_h, p1->g_y + p1->g_h);
  352.     tx = max(p2->g_x, p1->g_x);
  353.     ty = max(p2->g_y, p1->g_y);
  354.     p2->g_x = tx;
  355.     p2->g_y = ty;
  356.     p2->g_w = tw - tx;
  357.     p2->g_h = th - ty;
  358.     return( (tw > tx) && (th > ty) );
  359.     }
  360.  
  361.     VOID
  362. rc_union(p1, p2)
  363.     GRECT        *p1, *p2;
  364.     {
  365.     WORD        tx, ty, tw, th;
  366.  
  367.     tw = max(p1->g_x + p1->g_w, p2->g_x + p2->g_w);
  368.     th = max(p1->g_y + p1->g_h, p2->g_y + p2->g_h);
  369.     tx = min(p1->g_x, p2->g_x);
  370.     ty = min(p1->g_y, p2->g_y);
  371.     p2->g_x = tx;
  372.     p2->g_y = ty;
  373.     p2->g_w = tw - tx;
  374.     p2->g_h = th - ty;
  375.     }
  376.  
  377.     VOID
  378. rc_constrain(pc, pt)
  379.     GRECT        *pc;
  380.     GRECT        *pt;
  381.     {
  382.     if (pt->g_x < pc->g_x)
  383.         pt->g_x = pc->g_x;
  384.     if (pt->g_y < pc->g_y)
  385.         pt->g_y = pc->g_y;
  386.     if ((pt->g_x + pt->g_w) > (pc->g_x + pc->g_w))
  387.         pt->g_x = (pc->g_x + pc->g_w) - pt->g_w;
  388.     if ((pt->g_y + pt->g_h) > (pc->g_y + pc->g_h))
  389.         pt->g_y = (pc->g_y + pc->g_h) - pt->g_h;
  390.     }
  391.  
  392.     BOOLEAN
  393. inside(x, y, pt)        /* determine if x,y is in rectangle    */
  394.     UWORD        x, y;
  395.     GRECT        *pt;
  396.     {
  397.     if ( (x >= pt->g_x) && (y >= pt->g_y) &&
  398.         (x < pt->g_x + pt->g_w) && (y < pt->g_y + pt->g_h) )
  399.         return(TRUE);
  400.     else
  401.         return(FALSE);
  402.     } /* inside */
  403.  
  404.